package com.chandra.pos.customer.service;

import com.chandra.pos.customer.dao.entity.Customer;
import com.chandra.pos.customer.dao.ICustomerDAO;
import com.chandra.pos.customer.exception.CustomerNotFoundException;
import com.chandra.pos.customer.model.CustomerSearchCriteria;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.transaction.annotation.Transactional;

import javax.inject.Inject;
import javax.inject.Named;
import java.util.List;

/**
 * 
 * Customer Service
 * 
 * @author onlinetechvision.com
 * @since 25 Mar 2012
 * @version 1.0.0
 *
 */
@Transactional(readOnly = true)
@Named
public class CustomerService implements ICustomerService {

	// CustomerDAO is injected...
    @Inject
    ICustomerDAO userDAO;
	
	/**
	 * Add Customer
	 * 
	 * @param  User customer
	 */
	@Transactional(readOnly = false)
	@Override
	public void addUser(Customer customer) {
        userDAO.addUser(customer);
	}

	/**
	 * Delete Customer
	 * 
	 * @param  User customer
	 */
	@Transactional(readOnly = false)
	@Override
	public void deleteUser(Customer customer) {
        userDAO.deleteUser(customer);
	}
	
	/**
	 * Update Customer
	 * 
	 * @param  customer customer
	 */
	@Transactional(readOnly = false)
	@Override
	public void updateUser(Customer customer) {
        userDAO.updateUser(customer);
	}
	
	/**
	 * Get Customer
	 * 
	 * @param  id Customer Id
	 */
	@Override
	public Customer getUserById(Long id) {
		return userDAO.getUserById(id);
	}

    @Override
    public Customer markAsCustomer(Customer customer) {
        return userDAO.markAsCustomer(customer);
    }

    @Override
    public List<Customer> searchUsers(String s) {
        return userDAO.searchUsers(s);  //To change body of implemented methods use File | Settings | File Templates.
    }

    /**
	 * Get Customer List
	 * 
	 */
	@Override
	public Page getUsers(PageRequest posPagination) {
		return userDAO.getUsers(posPagination);
	}

    @Override
    public List<Customer> searchUsers(CustomerSearchCriteria searchCriteria) {
        return userDAO.searchUsers(searchCriteria);  //To change body of implemented methods use File | Settings | File Templates.
    }

     @Override
    public Customer getCustomerDetail(String firstName,String lastName,String city) throws CustomerNotFoundException{
        return userDAO.getCustomerDetail(firstName, lastName, city);  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public Customer getCustomerDetail(Long id) throws CustomerNotFoundException {
        return userDAO.getCustomerDetail(id);  //To change body of implemented methods use File | Settings | File Templates.
    }



}
